using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace EuropeEngulfed.NET
{
    class ColourMappedUIImage
    {
        protected Bitmap mainImage;
        protected Bitmap mappedUIImage;
        protected List<UIRegion> UIRegions;

        public ColourMappedUIImage()
        {
            mainImage = null;
            mappedUIImage = null;
            UIRegions = null;
        }

        public Image MainImage
        {
            get
            {
                return mainImage;
            }
        }

        public Image MappedMainImage
        {
            get
            {
                return mappedUIImage;
            }
        }

        public UIRegion GetUIRegion(int xPos, int yPos)
        {
            if (UIRegions != null)
            {
                if (mappedUIImage != null)
                {
                    try
                    {
                        Color colorAtPoint = mappedUIImage.GetPixel(xPos, yPos);
                        foreach (UIRegion UIRegionToTest in UIRegions)
                        {
                            if (UIRegionToTest.MappedUIColor.Equals(colorAtPoint))
                                return UIRegionToTest;
                        }
                    }
                    catch (System.ArgumentOutOfRangeException)
                    {
                    }
                }
                else
                    System.Diagnostics.Debug.Assert(false, "mapped UI Image not initialised");
            }
            return null;
        }
    }
}
